package com.atguigu.test

import org.apache.flink.streaming.api.scala._
import org.apache.flink.streaming.api.windowing.time.Time

object WordCount_online {


  case class Word(str: String, i: Int)


  def main(args: Array[String]): Unit = {
    // 创建流处理环境
    val env = StreamExecutionEnvironment.getExecutionEnvironment
    //设置分区数量为1
    //申请一个任务插槽
    env.setParallelism(1)
    val stream =env.socketTextStream("hadoop102",9999,' ')
    val tr = stream
      .flatMap(line => line.split(" "))
      .map(w => Word(w, 1))
      .keyBy(0)
      .timeWindow(Time.seconds(5))
      .sum(1)
    tr.print()

    //执行计算逻辑
    env.execute()


  }
}
